
// 侧边推荐
axios.get('/index/recommend')
  .then(res => {
    // console.log(res.data.list)
    const advrelind = res.data.list.map(({ catename, pic, title, lovenum, id }) => {
      return `
      <li>
      <a target="_blank" href="">
        <span class="thumbnail">
          <img src="http://124.223.14.236:8060/${pic}" class="thumb" />
        </span>
        <span class="text">${title}</span>
        <span class="text-muted post-views">阅读(${lovenum})</span>
      </a>
    </li>
              `
    }).join('')
    document.querySelector('.widget ul').innerHTML = advrelind

    document.querySelector('.widget_postlist .items-01').innerHTML = advrelind
  })



// 基础数据
axios.get('/index/index')
  .then(res => {
    console.log(res)
    // console.log(res.data.banner)
    const adv = res.data.banner.map(({ advimgdesc, advimglink, advimgsrc }) => {
      // if (advimgsrc, advimglink, advimgdesc) {
      return `
          <li class="large">
             <a target="_blank" href=${advimglink}>
              <img class="thumb" src="http://124.223.14.236:8060/${advimgsrc}" />
            <h4>${advimgdesc}</h4>
           </a>
           </li>
        `
      // }
    }).join('')
    // console.log(adv, 'advadv');
    document.querySelector('.demoimg ul').innerHTML = adv
    ins.reload()
    //导航
    $('.nav').append(res.data.allCate.map(({catename,icon,id}) => {
      return `
      <li  class="menu-item menu-item-type-taxonomy menu-item-object-category" data-id =${id}><a href="list.html"><span
                class="fa ${icon}"></span>${catename}</a></li>
      `
    }).join('')) 
    //通知公告
    // const widget_textssr = document.querySelector('.widget_textssr')
    // const newArr  = res.data.config.allData.filter((item) => {
    //     if (item.id === 78017) {
    //         return `
          
    //         `
    //       }
    //       widget_textssr.innerHTML = newArr
    //     })
        // 右侧广告位
    // console.log(res.data.sideBanner);
    const advreg = res.data.sideBanner.map(({ advimgdesc, advimglink, advimgsrc }) => {
      return `
      <a href="${advimglink}" rel="nofollow" target="_blank" title="${advimgdesc}">
      <img class="g430" style="width:360px;height:133px;" src="http://124.223.14.236:8060/${advimgsrc}" alt="${advimgdesc}">
    </a>
      `
    }).join('')
    document.querySelector('.sidebar .textwidget').innerHTML = advreg


    // console.log(res.data.allTag);
    const advremen = res.data.allTag.map(({ tagname }) => {
      return `
      <li><a title="" href="">${tagname}</a></li>
      `
    }).join('')
    document.querySelector('.widget .widget_tags_inner').innerHTML = advremen

       

    // 友情链接

    // console.log(res.data.allLink);
    const advlink = res.data.allLink.map(({ des, img, url }) => {
      if (des, img) {
        return `
        <li>
        <a href="${url}"><img src="http://124.223.14.236:8060/${img}" alt="">
          <p>${des}</p>
        </a>
      </li>
        `
      }
    }).join('')
    document.querySelector('.widget_comments ul').innerHTML = advlink

    // console.log(res.data.allLink);
    const advlink2 = res.data.allLink.map(({ des, img, url }) => {
      if (img) {
        return `
        <a href="${url}" title="${des}">${des}</a> <span>|</span>
        `
      }
    }).join('')
    document.querySelector('.footer .link').innerHTML = advlink2
  })

var ins = null
layui.use(function () {
  carousel = layui.carousel;
  // 渲染 - 图片轮播
  ins = carousel.render({
    elem: '#ID-carousel-demo-image',
    width: '720px',
    height: '360px',
    interval: 3000
  });
});


axios.get('/index/hot')
  .then(res => {
    // console.log(res)
    const advhot = res.data.list.map(({ catename, id, pic, title }) => {
      return `
       <li class="item"><a target="_blank" href="/show.html"><img src="http://124.223.14.236:8060/${pic}"
       class="thumb" />${title}</a></li>
      `
    }).join('')
    document.querySelector('.sticky ul').innerHTML = advhot

  })


axios.get("/index/new")
  .then(res => {
    console.log(res)
    // console.log(res.data.list.data)
    const author = res.data.list.data.map(({ author, catename, click, create_date, description, id, ishot, istop, keywords, lovenum, pic, tags, title }) => {
      return `
        <article class="excerpt excerpt-one">
        <header>
          <a class="cat label label-important" href="">热门<i class="label-arrow"></i></a>
          <h2>
            <a target="_blank" href="show.html?id=${id}" title="${title}">${title}data-id=</a>
          </h2>
        </header>
        <p class="text-muted time">
          <a href="">${author}</a> 发布于 ${new Date(create_date).toLocaleString()}
        </p>
        <p class="focus">
          <a target="_blank" href="" class="thumbnail">
            <span class="item"><span class="thumb-span"><img src="http://124.223.14.236:8060/${pic}"
                  class="thumb" /></span></span></a>
        </p>
        <p class="note">${description}</p>
        <p class="text-muted views">
          <span class="post-views">阅读(${click})</span>
          <span class="post-comments">评论(0)</span>
          <a href="javascript:;" class="post-like">
            <i class="fa fa-thumbs-up"></i>赞 (<span>${lovenum}</span>)
          </a>
          <span class="post-tags">标签：
            <a href="" rel="tag">${tags}</a> /
            <a href="" rel="tag">阿里云</a></span>
        </p>
      </article>
          `
    }).join('')

    document.querySelector('.link-tem').innerHTML = author
  })
  ; (async function () {
    const { data: { config: { allData } } } = await axios.get('/index/index')
    // console.log(allData);
    const widget_textssr = document.querySelector('.widget_textssr')
    const data = allData.filter((item) => item.id === 78017)
    // console.log(data);
    const newArr = data.map((item) => {
      
      return `
        <a class="style02" href="http://www.thefox.cn/alibaixiu.shtml"
          target="_blank"><strong>通知公告</strong>
          <h2>感谢广大好友</h2>  
          <p>${item.attr_value}</p>
        </a>
        `
      
    }).join('')
    widget_textssr.innerHTML = newArr
  })()
  ; (function () {
    
  })()
  ; ( function () {
    
    $('.link-tem').on('click', 'a', function () {
      // axios.get('/index/show')
      // .then(res => {
      //   console.log(res)
      // })
     
      let id = $(this).attr('data-id')
      location.href = '/show.html?id=' + id
    })
  })()